<template>
	<view class="columnbox wdh-100 content">
		<view class="columnbox one-member" v-for="(item,index) in list" :key='index'>
			<view class="top-box rowbox wdh-100">
				<view class="user-name">{{item.phone}}</view>
				<view class="add-time">添加时间：{{item.create_time}}</view>
			</view>
			<view class="rowbox wdh-100 manage-box">
				<!-- <view>手机号：{{item.phone}}</view> -->
				<view></view>
				<view class="delet-btn rowbox def-bgcol" @click="deletMember(item)">删除</view>
			</view>
		</view>
		<view class="wdh-100" style="height: 200rpx;"></view>
		<view class="add-btn rowbox def-bgcol" @click="addMember">
			添加成员
		</view>
		<u-popup mode="center" :show="addflag" round="10">
			<view class="add-box columnbox">
				<input v-model="phonenum" class="input-box" placeholder="请输入店员手机号" />
				<input v-model="name" class="input-box" placeholder="请输入店员姓名" />
				<view @click="searchMember" class="def-bgcol rowbox confirm-btn">确定</view>
			</view>
		</u-popup>
		<u-popup mode="center" :show="searchflag" round="10">
			<view class="add-box columnbox">
				<view class="columnbox one-member search-info">
					<view class="top-box rowbox wdh-100">
						<view class="user-name">{{staffss.nickname}}</view>
					</view>
					<view class="rowbox wdh-100 manage-box">
						<view>手机号：{{staffss.phone}}</view>
						<view @click="setStaff" class="delet-btn rowbox def-bgcol">设置店员</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import getdate from '@/utils/time.js'
	export default {
		data() {
			return {
				name: '',
				list: [],
				addflag: false,
				searchflag: false,
				phonenum: '',
				staffss: null
			};
		},
		onLoad() {
			this.getInfo()
		},
		methods: {
			deletMember(val) {
				uni.showModal({
					title: '是否要删除该员工',
					success: (res) => {
						if (res.confirm) {
							this.$req.post('/shanghu/staffdel', {
								phone: val.phone
							}).then(res => {
								this.list = []
								this.getInfo()
							})
						}
					}
				})
			},
			setStaff() {
				uni.showModal({
					title: '是否确认设置店员',
					success: (res) => {
						if (res.confirm) {
							this.$req.post('/shanghu/staffadd', {
								shanghuid: uni.getStorageSync('userInfo').shanghuid,
								phone: this.staffss.phone,
								name: this.name
							}).then(res => {
								if (res.data.code === 0) {
									this.searchflag = false
									this.phonenum = ''
									this.name = ''
									this.list = []
									this.getInfo()
								} else {
									this.searchflag = false
									this.phonenum = ''
									this.name = ''
									uni.showToast({
										title: res.data.msg,
										icon: 'none'
									})
								}

							})
						}
					}
				})
			},
			getInfo() {
				this.$req.post('/shanghu/staff', {
					shanghuid: uni.getStorageSync('userInfo').shanghuid
				}).then(res => {
					res.data.data.forEach(resp => {
						resp.create_time = getdate.couponDate(resp.create_time)
					})
					this.list = res.data.data
				})
			},
			addMember() {
				this.addflag = true
			},
			searchMember() {
				if (this.phonenum == '') {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					})
					return
				}
				if (!this.name) {
					uni.showToast({
						title: '请输入姓名',
						icon: 'none'
					})
					return
				}

				this.$req.post('/shanghu/staffss', {
					phone: this.phonenum,

				}).then(res => {
					if (res.data.data.id != 0) {
						this.staffss = res.data.data
						this.searchflag = true
						this.addflag = false
					} else {
						uni.showModal({
							title: '未搜索到员工'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background: #f6f6f6;
		justify-content: flex-start;
	}

	.one-member {
		background: #fff;
		width: 710rpx;
		padding: 32rpx 32rpx;
		margin-top: 20rpx;
		border-radius: 20rpx;
	}

	.top-box {
		justify-content: space-between;
	}

	.user-name {
		font-size: 32rpx;
		font-weight: bold;
	}

	.add-time {
		font-size: 28rpx;
		color: #77787a;
	}

	.manage-box {
		margin-top: 20rpx;
		justify-content: space-between;
	}

	.delet-btn {
		color: #fff;
		line-height: 50rpx;
		font-size: 24rpx;
		padding: 0 20rpx;
		border-radius: 10rpx;
	}

	.add-btn {
		color: #fff;
		width: 710rpx;
		height: 90rpx;
		border-radius: 20rpx;
		position: fixed;
		bottom: 40rpx;
		left: 20rpx;
	}

	.add-box {
		width: 600rpx;
		padding: 20rpx 20rpx;
	}

	.input-box {
		background: #f6f6f6;
		width: calc(100% - 40rpx);
		margin-top: 20rpx;
		font-size: 28rpx;
		height: 100rpx;
		padding: 0 20rpx;
	}

	.confirm-btn {
		width: 400rpx;
		color: #fff;
		font-size: 28rpx;
		height: 70rpx;
		margin-top: 40rpx;
		border-radius: 20rpx;
	}

	.search-info {
		width: 100%;
	}
</style>